package com.fpno1.update;

import com.fpno2.JDBCUtil.JDBCUtils;
import org.junit.Test;
import sun.security.jca.GetInstance;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class PreparedStatementTest1 {
    @Test
    public void testLogin() throws Exception {
        Scanner sc=new Scanner(System.in);
        System.out.print("请输入用户名:");
        String user = sc.nextLine();
        System.out.print("请输入密码:");
        String password = sc.nextLine();
        String sql="select user,password from user_table where user=? and password=?";
        User returnUser =getInstance(User.class, sql, user, password);
        if (returnUser!=null){
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }


    }

    public<T> T  getInstance(Class cla,String sql,Object... args) throws Exception {
        Connection con = JDBCUtils.getConnection();
        PreparedStatement ps = con.prepareStatement(sql);
        for (int i=0;i<=args.length;i++){ 
            ps.setObject(i+1,args[i]);
        }
        ResultSet rs = ps.executeQuery();



        return null;
    }
}
